﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using Microsoft.Office.Tools;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Xml;
using System.Reflection;

namespace Test
{
    public class ExportDataToExcel
    {
        private static Excel.XmlMap xmlMap;
        public static void Test()
        {
            Excel.Application app = new Excel.Application();
            app.Visible = true;
            Excel.Workbook workBook= app.Workbooks.Add();

            string text = GetSchema();
            xmlMap = workBook.XmlMaps.Add(text, "table");
            xmlMap.Name = "中辰照明数据源";
            
        }

        public static void Generate()
        {
            xmlMap.ImportXml(GetData());
        }

        private static string GetSchema()
        {
            string text = null;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Test.schame.xsd"))
            {
                TextReader reader = new StreamReader(stream);
                text = reader.ReadToEnd();
            }

            return text;
        }

        private static string GetData()
        {
            string text = null;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Test.table1.xml"))
            {
                TextReader reader = new StreamReader(stream);
                text = reader.ReadToEnd();
            }

            return text;
        }
    }
}
